package com.dominator.api.controller;

import com.dominator.api.common.WebCxt;
import com.dominator.api.common.wrapper.Dto;
import com.dominator.api.enums.ReqEnums;
import com.dominator.api.service.EmailService;
import com.dominator.api.utils.api.ApiMessage;
import com.dominator.api.utils.exception.ApiException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/v1/email")
public class EmailController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    EmailService emailService;


    @RequestMapping("/sendRegist")
    public ApiMessage sendRegist(){
        ApiMessage apiMessage=new ApiMessage();
        try {
            Dto dto= WebCxt.getParamAsDto(request);
            apiMessage=emailService.sendRegist(dto);
        }catch (ApiException e){
            apiMessage.setCode(e.getCode());
            apiMessage.setMessage(e.getMessage());
        }catch (Exception e){
            apiMessage =new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return apiMessage;
    }


}
